#include <stdio.h>

#include "nuclei_sdk_hal.h"
#include "nuclei_libopt.h"

#define ARR_SIZE 10

uint8_t uart0_send_buffer[ARR_SIZE]={ 0x11 ,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a};
uint8_t err_count=0;
uint8_t state=0;

void uart0_handler(void)
{
    if(uart_get_error_overflow(UART0)!=0)
    {
        err_count++;
    }
}



void main(void )
{
    __enable_irq();
	ECLIC_Register_IRQ(UART0_IRQn, ECLIC_NON_VECTOR_INTERRUPT,
                                    ECLIC_LEVEL_TRIGGER, 1, 1,
                                    uart0_handler);	
    uart_init(UART0, 115200,UART_BIT_LENGTH_7);

    uart_enable_ov_irq(UART0);

    for(uint8_t i=0 ; i<10 ;i++)
    {
        uart_write(UART0,uart0_send_buffer[i]);
         delay_1ms(100);
    }

    while(err_count<2);
    if(err_count==2)
    {
        state=1;
    }

    #ifdef CFG_SIMULATION
        pass_fail_simulation(state);
    #endif 
    if(err_count==2){
         gd_eval_led_on(LED2);
    }else{
        while(1){
            gd_eval_led_toggle(LED2);
            delay_1ms(500);
        }
    }

    while(1);

    return;
}
